package com.zbkj.admin.controller.platform.community;

import com.zbkj.common.model.community.CommunityQuestion;
import com.zbkj.common.page.CommonPage;
import com.zbkj.common.request.CommunityQuestionRequest;
import com.zbkj.common.request.CommunityQuestionSearchRequest;
import com.zbkj.common.request.PageParamRequest;
import com.zbkj.common.result.CommonResult;
import com.zbkj.service.community.CommunityQuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * 社区问题表 前端控制器
 */
@Slf4j
@RestController
@RequestMapping("api/admin/platform/community/question")
@Api(tags = "社区问题表") //配合swagger使用

public class CommunityQuestionController {

    @Autowired
    private CommunityQuestionService communityQuestionService;

    /**
     * 分页显示社区问题表
     * @param request 搜索条件
     * @param pageParamRequest 分页参数
     * @author keNan
     * @since 2025-06-26
     */
    @ApiOperation(value = "分页列表") //配合swagger使用
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public CommonResult<CommonPage<CommunityQuestion>>  getList(@Validated CommunityQuestionSearchRequest request, @Validated PageParamRequest pageParamRequest) {
        CommonPage<CommunityQuestion> communityQuestionCommonPage = CommonPage.restPage(communityQuestionService.getList(request, pageParamRequest));
        return CommonResult.success(communityQuestionCommonPage);
    }

    /**
     * 新增社区问题表
     * @param communityQuestionRequest 新增参数
     * @author keNan
     * @since 2025-06-26
     */
    @ApiOperation(value = "新增")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public CommonResult<String> save(@RequestBody @Validated CommunityQuestionRequest communityQuestionRequest) {
        CommunityQuestion communityQuestion = new CommunityQuestion();
        BeanUtils.copyProperties(communityQuestionRequest, communityQuestion);

        if(communityQuestionService.save(communityQuestion)) {
            return CommonResult.success();
        } else {
            return CommonResult.failed();
        }
    }

    /**
     * 删除社区问题表
     * @param id Integer
     * @author keNan
     * @since 2025-06-26
     */
    @ApiOperation(value = "删除")
    @RequestMapping(value = "/delete", method = RequestMethod.GET)
    public CommonResult<String> delete(@RequestParam(value = "id") Integer id) {
        if(communityQuestionService.removeById(id)) {
            return CommonResult.success();
        } else {
            return CommonResult.failed();
        }
    }

    /**
     * 修改社区问题表
     * @param communityQuestionRequest 修改参数
     * @author keNan
     * @since 2025-06-26
     */
    @ApiOperation(value = "修改")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public CommonResult<String> update(@RequestBody @Validated CommunityQuestionRequest communityQuestionRequest) {
        CommunityQuestion communityQuestion = new CommunityQuestion();
        BeanUtils.copyProperties(communityQuestionRequest, communityQuestion);

        if(communityQuestionService.updateById(communityQuestion)) {
            return CommonResult.success();
        } else {
            return CommonResult.failed();
        }
    }

    /**
     * 查询社区问题表信息
     * @param id Integer
     * @author keNan
     * @since 2025-06-26
     */
    @ApiOperation(value = "详情")
    @RequestMapping(value = "/info", method = RequestMethod.GET)
    public CommonResult<CommunityQuestion> info(@RequestParam(value = "id") Integer id) {
        CommunityQuestion communityQuestion = communityQuestionService.getById(id);
        return CommonResult.success(communityQuestion);
    }
}



